﻿using Anke.SHManage.BLL;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.DD.Controllers
{
    public class TelRecordController : Controller
    {
        private static object m_SyncRoot = new Object();//互斥对象
        //
        // GET: /DD/TelRecord/

        public ActionResult TelRecordList()
        {
            this.ViewData["start"] = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
            this.ViewData["end"] = DateTime.Now.AddHours(1).ToString("yyyy-MM-dd HH:mm:ss");
            return View();
        }

        //查询电话流水
        public ActionResult DataLoad()
        {
            //获取页容量
            int pageSize = int.Parse(Request.Form["rows"]);
            //获取请求的页码
            int pageIndex = int.Parse(Request.Form["page"]);
            //获取查询条件
            DateTime start = Convert.ToDateTime(Request.Form["start"]);
            DateTime end = Convert.ToDateTime(Request.Form["end"]);
            string callPhone = Request.Form["callNumber"];
            string workCode = Request.Form["workCode"];
            string deskCode = Request.Form["deskCode"];
            string resultType = Request.Form["resultType"];
            string isCallOut = Request.Form["isCallOut"];
            string isInLine = Request.Form["isInLine"];
            string isWireless = Request.Form["isWireless"];          

            E_StatisticsPermisson em = UserOperateContext.Current.getMaxPerForStatistics();
            string selfWorkCode = UserOperateContext.Current.Session_UsrInfo.WorkCode;
            string selfCenterID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID;
            string selfStationID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID;
            string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-22 zch 登录人所处急救中心
            TelRecordBLL bll = new TelRecordBLL();

            //2023-08-07 plq 查询页添加SQL防注入
            if (ControlHelper.ProcessSqlStr(start.ToString()) && ControlHelper.ProcessSqlStr(end.ToString()) && ControlHelper.ProcessSqlStr(callPhone)
               && ControlHelper.ProcessSqlStr(workCode) && ControlHelper.ProcessSqlStr(deskCode) && ControlHelper.ProcessSqlStr(resultType)
               && ControlHelper.ProcessSqlStr(isCallOut) && ControlHelper.ProcessSqlStr(isInLine) && ControlHelper.ProcessSqlStr(isWireless))
            {
                var list = bll.GetTelRecordList(pageSize, pageIndex, start, end, callPhone, workCode, deskCode, resultType, isCallOut,
                                                isInLine, isWireless, em, selfWorkCode, selfCenterID, selfStationID, eventDispatchCenterID);

                JsonResult j = this.Json(list, "appliction/json", JsonRequestBehavior.AllowGet);
                return j;
            }
            else
            {
                return Json(new { total = 0, rows = "dangerousInfomation" }, "appliction/json", JsonRequestBehavior.AllowGet);
            }

        }


        // 获取台号     
        [HttpPost]
        public ActionResult GetDeskCode()
        {
            try
            {
                TelRecordBLL bll = new TelRecordBLL();
                var result = new object();
                //增加缓存
                lock (m_SyncRoot)
                {
                    result = CacheHelper.GetCache("GetDeskCode");
                    if (result == null)
                    {
                        string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2021-06-05 gdg 登录人所处急救中心
                        result = bll.GetDeskCodeList(eventDispatchCenterID);
                        CacheHelper.SetCache("GetDeskCode", result);
                    }
                }
                return Json(result);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

        /// <summary>
        /// 取TelLog结果类型
        /// add2021-07-02 plq
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetCallResultType()
        {
            try
            {
                var list = new TelRecordBLL().GetCallResultType();
                return Json(list);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }


    }
}
